package com.wanmei.util;

import java.util.regex.Pattern;

public class VolidatorUtil {
    /**
     * 正则表达式：验证邮箱
     */
    public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    /**
     * 正则表达式：验证手机号
     */
    public static final String REGEX_MOBILE = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
    /**
     * 正则表达式：验证密码
     */
    public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]{5,15}$";
    /**
     * 校验正整数
     */
    public static final String REGEX_Number = "^\\d{0,8}$";

    public static boolean isInteger (String str){
        return  Pattern.matches(REGEX_Number,str);
    }
    public static boolean isEmail(String str) {
        return Pattern.matches(REGEX_EMAIL, str);
    }

    public static boolean isMobile(String str) {
        return Pattern.matches(REGEX_MOBILE, str);
    }

    public static boolean isPassword(String str) {
        return Pattern.matches(REGEX_PASSWORD, str);
    }

    /**
     * 验证是否字符串是正整数
     *
     * @param str
     * @return
     */
    public static boolean isNumber(String str) {
        char[] c = str.toCharArray();
        boolean b;
        for (int i = 0; i < c.length; i++) {
            b = Character.isDigit(c[i]);
            if (b == false) {
                return false;
            }
        }
        return true;
    }
}
